package cn.hiapi.shopkeeper.task;

import cn.hiapi.basic.jpa.pageable.QueryWrapper;
import cn.hiapi.interfaces.DispatchContext;
import cn.hiapi.shopkeeper.entity.activity.Activity;
import cn.hiapi.shopkeeper.service.activity.ActivityService;
import cn.hiapi.shopkeeper.task.abs.AbsTaskService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author AdinZ
 * @date 2023/1/2 21:14
 */
@Component
public class ActivityTaskService extends AbsTaskService {

    public ActivityTaskService(DispatchContext dispatchContext) {
        super(dispatchContext);
    }

    /**
     * 监听活动结束任务
     */
    @Scheduled(cron = "0/10 * * * * ?")
    public void activityEnd() {
        //结束的活动列表
        List<Activity> list = this.dispatchContext.getServiceOne(ActivityService.class).findList(new QueryWrapper()
                .eq("status", 1).le("endTime", System.currentTimeMillis()));
        this.dispatchContext.getServiceOne(ActivityService.class).activityEnd(list);
    }


    @Scheduled(cron = "0/10 * * * * ?")
    public void activityUseEnd() {
        List<Activity> list = this.dispatchContext.getServiceOne(ActivityService.class).findList(new QueryWrapper()
                .eq("useStatus", 0).le("useEnd", System.currentTimeMillis()));
        this.dispatchContext.getServiceOne(ActivityService.class).activityUseEnd(list);
    }


}
